#include <iostream>
using namespace std;
#define LL long long

const LL mod = 1000000007;

LL n;
int m;

struct device
{
    LL x;
    LL y;
    LL z;
    device(){
        x=y=z=0;
    }
};

device* dev;

device a;

void increase(LL L, LL R, LL a, LL b, LL c)
{
    for (LL i = L; i <= R; i++)
    {
        dev[i].x += a;
        dev[i].y += b;
        dev[i].z += c;
    }
}

void add(LL L, LL R, LL k)
{
    for (LL i = L; i <= R; i++)
    {
        dev[i].x = (k*dev[i].x)%mod;
        dev[i].y = (k*dev[i].y)%mod;
        dev[i].z =(k*dev[i].z)%mod;
    }

}

void turn(LL L, LL R)
{
    for (LL i = L; i <= R; i++)
    {
        LL temp1 = dev[i].x, temp2 = dev[i].y, temp3 = dev[i].z;
        dev[i].x = temp2;
        dev[i].y = temp3;
        dev[i].z = temp1;
    }
}

void query(LL L, LL R)
{
    a.x=a.y=a.z=0;
    for (LL i = L; i <= R; i++)
    {
        a.x += dev[i].x;
        a.y += dev[i].y;
        a.z += dev[i].z;
    }
    a.x %=mod;
    a.y %=mod;
    a.z%=mod;
    cout << ((a.x * a.x) %mod+ (a.y * a.y)%mod + (a.z * a.z)%mod) % mod << endl;
}

int main()
{
    cin >> n >> m;
    dev = new device[n+10];
    for (int i = 0; i < m; i++)
    {
        int op;
        LL L, R, a, b, c, k;
        cin >> op;
        if (op == 1)
        {
            cin >> L >> R >> a >> b >> c;
            increase(L, R, a, b, c);
        }
        else if (op == 2)
        {
            cin >> L >> R >> k;
            add(L, R, k);
        }
        else if (op == 3)
        {
            cin >> L >> R;
            turn(L, R);
        }
        else
        {
            cin >> L >> R;
            query(L, R);
        }
    }
    delete[] dev;
    system("pause");
    return 0;
}